package com.inetools.gwetons.logging.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.junit.client.GWTTestCase;
import com.inetools.gwetons.client.logging.JsniLogUtil;
import com.inetools.gwetons.client.logging.JsniLogUtilFactory;
import com.inetools.gwetons.client.logging.JsniLogUtilFactoryInterface;
import com.inetools.gwetons.logging.shared.LoggerInitializerForTest;
import com.inetools.gwetons.shared.logging.LogUtil;
import com.inetools.gwetons.shared.logging.LogUtilFactoryIntf;

public abstract class JsniLogUtilAdaptedGwtTestCase extends GWTTestCase {
	// For logging --------------------------------------------------------------------------------
	abstract protected String getNameForLogging();
	
	private static LoggerInitializerForTest loggerInitializerForTest;
		public static LoggerInitializerForTest getLoggerInitializerForTest() {
			if ( loggerInitializerForTest == null) {
				LoggerInitializerForTestGinjector loggerInitializerForTestGinjector 
				= GWT.create( LoggerInitializerForTestGinjector.class);
				setLoggerInitializerForTest(
						loggerInitializerForTestGinjector.getLoggerInitializerForTest()
						);
			}
			return loggerInitializerForTest;
		}
		public static void setLoggerInitializerForTest( 
				LoggerInitializerForTest loggerInitializerForTest) {
			
			JsniLogUtilAdaptedGwtTestCase.loggerInitializerForTest = loggerInitializerForTest;
		}

	private JsniLogUtilFactoryInterface jsniLogUtilFactoryInterface;
		public JsniLogUtilFactoryInterface getJsniLogUtilFactoryInterface() {
			return jsniLogUtilFactoryInterface;
		}
		public void setJsniLogUtilFactoryInterface( 
				JsniLogUtilFactoryInterface jsniLogUtilFactoryInterface) {
			
			this.jsniLogUtilFactoryInterface = jsniLogUtilFactoryInterface;
			setLogUtil( null);
		}

		public LogUtilFactoryIntf getLogUtilFactoryIntf() {
			return getJsniLogUtilFactoryInterface();
		}
		
	private LogUtil logUtil;
		private LogUtil getLogUtil() {
			return logUtil;
		}
		public void setLogUtil( LogUtil logUtil) {
			this.logUtil = logUtil;
			setJsniLogUtil( null);
		}
		
	private JsniLogUtil jsniLogUtil;
		public JsniLogUtil getJsniLogUtil() {
			if ( jsniLogUtil == null) {
				setJsniLogUtil( 
						JsniLogUtilFactory.getJsniLogUtil( 
								null, 
								getLogUtil(), 
								getNameForLogging(), 
								getJsniLogUtilFactoryInterface()
								)
						);
			}
			return jsniLogUtil;
		}
		public void setJsniLogUtil(JsniLogUtil jsniLogUtil) {
			this.jsniLogUtil = jsniLogUtil;
		}
	// --------------------------------------------------------------------------------------------
}
